<template>
  <j-modal title="相关操作单位" :width="800" :visible="visible" switchFullscreen @cancel="handleCancel" @ok="handleOk" >
    <div>
      <div class="table-page-search-wrapper">
        <a-form-model layout="inline" ref="ruleForm" :model="queryParam" >
          <z-form-item :datas="fieldArr" :form="queryParam" :gutter="24" :toggle="toggleSearchStatus">
            <a-col :span="8" slot="submit-action">
              <a-space :size="6">
                <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                <a-button @click="onResetForm" icon="reload">重置</a-button>
              </a-space>
            </a-col>
          </z-form-item>
        </a-form-model>
      </div>
      <z-table
        ref="table"
        rowKey="id"
        :showAlert="false"
        :showSelection="true"
        :loading="loading"
        :columns="columns"
        :dataSource="pageData"
        :rowSelection="{selectedRowKeys: selectedRowKeys1, onChange: onSelectChange1, type:'radio'}"
        @selectedRow="onSelectedRow"
        @change="onTableChange"
      ></z-table>
    </div>
  </j-modal>
</template>
<script>
// import {administrotorsList, getSetId, putFile, saverSetup} from "@api/sjsk/specialist";
import Vue from "vue";
import {USER_INFO} from "@/store/mutation-types";
// import * as flowServiceApi from "@api/sjsk/flowService";
// import {referral} from "@api/sjsk/receiveCase";
import {getAction} from "@api/manage";
import * as warningApi from "@api/warning/WarningData";

export default {
  name: 'AddModal',
  data() {
    return {
      toggleSearchStatus:true,
      queryParam:{},
      visible: false,
      loading:false,
      showAdmin:false,
      pageFilter: {
        pageNo: 1,
        pageSize: 10
      },
      fieldArr: [
        {label: '单位名称', prop: 'officeName', tagType: 'input', span: 12}
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        //
        {
          title: '创建人',
          align: 'left',
          dataIndex: 'createBy',
          customRender: text => {
            return <j-ellipsis value={text} length={20} />
          }
        },
        {
          title: '单位名称',
          dataIndex: 'officeName',
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={20} />
          }
        },
      ],
      pageData:[

      ],
      selectedRowKeys1: [],
      referralData:{}
    }
  },
  created() {

  },
  methods: {
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },
    onResetForm() {
      this.pageFilter = {
        pageNo: 1,
        pageSize: 10,
      }
      this.queryParam = {}
      this.refreshTable()
    },
    show(record) {
      this.visible = true
      this.referralData.id = record
      this.refreshTable()
    },
    showAdminFun() {
      this.visible = true
      this.showAdmin = true
      this.refreshTable()

    },
    onStartChange() {

    },
    onSelectedRow(keys) {
      this.selectKeys = keys
      this.isDisabled = keys.length <= 0
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      let form = Object.assign({}, this.queryParam, this.pageFilter)
      this.loading = true
      warningApi.rootList(form)
        .then(res => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            this.$refs.table.onClearRowKeys()
          } else {
            this.loading = false
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },




    onChange(e) {
      if (e.target.value == '2') {
        this.isPositive = true
      } else {
        this.isPositive = false
      }
      console.log('radio checked', e.target.value);
    },
    onSwitchChange(e) {
      console.log(e);
      if (e) {
        this.isPolice = true
      } else {
        this.isPolice = false
      }
    },
    handleCancel() {
      this.visible = false
      this.queryParam = {}
    },
    handleOk() {
      if(this.showAdmin){
        console.log(this.referralData)
        this.$emit('ok',this.referralData)
        this.visible = false
      } else {
        referral(this.referralData).then(ser => {
          if(ser.success){
            this.$message.success('转介成功')
            this.visible = false
          } else {
            this.$message.error(ser.message)
          }
        })
      }

    },
    getContent(index, key) {
      let col = this.list.find((col, i) => i === index)
      if (col && Object.keys(col).length>0) {
        return col[key]
      }
    },
    onSelectChange1(selectedRowKeys, selectionRows) {
      /*
      departmentId部门ID
      region部门名称
      id人员id
      personnelName，人员名称
       */
      this.selectedRowKeys1 = selectedRowKeys
      this.referralData.officeCode = selectionRows[0].officeCode
      this.referralData.officeName = selectionRows[0].officeName
      // console.log(selectionRows,selectedRowKeys)
    },
    loadData2(arg) {
      if (!this.url.list2) {
        this.$message.error('请设置url.list2属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination2.current = 1
      }
      if (this.currentRoleId === '') return
      let params = this.getQueryParams2()//查询条件
      params.roleId = this.currentRoleId
      this.loading2 = true
      getAction(this.url.list2, params).then((res) => {
        if (res.success) {
          this.dataSource2 = res.result.records
          this.ipagination2.total = res.result.total

        }
        this.loading2 = false
      })

    },
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
//.l-form{
//  display: flex;
//  align-items: center;
//  margin-top: -5px;
//}
//.display>*{
//  margin: 5px;
//}
//.font-gray{
//  margin-top: 20px;
//  p {
//    font-size: 12px;
//  }
//}
//.green {
//  color: #52c41a;
//}
//.red {
//  color: #ff4d4f;
//}
//.blue {
//  color: #5a87db;
//}
</style>
